package longcaisuyun.longcai.com.yiliubabalongcaisuyun;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.util.UtilMD5;

import longcaisuyun.longcai.com.net.PostLogin;




//                            _ooOoo_
//                           o8888888o
//                           88" . "88
//                           (| -_- |)
//                            O\ = /O
//                        ____/`---'\____
//                      .   ' \\| |// `.
//                       / \\||| : |||// \
//                     / _||||| -:- |||||- \
//                       | | \\\ - /// | |
//                     | \_| ''\---/'' | |
//                      \ .-\__ `-` ___/-. /
//                   ___`. .' /--.--\ `. . __
//                ."" '< `.___\_<|>_/___.' >'"".
//               | | : `- \`.;`\ _ /`;.`/ - ` : | |
//                 \ \ `-. \_ __\ /__ _/ .-` / /
//         ======`-.____`-.___\_____/___.-`____.-'======
//                            `=---='
//
//         .............................................
//         佛祖保佑             永无BUG
//         佛曰:
//                  写字楼里写字间，写字间里程序员；
//                  程序人员写程序，又拿程序换酒钱。
//                  酒醒只在网上坐，酒醉还来网下眠；
//                  酒醉酒醒日复日，网上网下年复年。
//                  但愿老死电脑间，不愿鞠躬老板前；
//                  奔驰宝马贵者趣，公交自行程序员。
//                  别人笑我忒疯癫，我笑自己命太贱；
//                  不见满街漂亮妹，哪个归得程序员？
/************************************************************/
//登录页面

/************************************************************/

public class LoginActivity extends Activity implements View.OnClickListener {

    Button bt_ok;
    TextView t_jiameng;
    TextView et_wangji;
    EditText et_name, et_pass;

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        View view = getWindow().getDecorView();
        MyApplication.ScaleScreenHelper.loadView((ViewGroup) view);
        ViewInit();
    }

    private void ViewInit() {
        bt_ok = (Button) findViewById(R.id.bt_ok);
        bt_ok.setOnClickListener(this);
        t_jiameng = (TextView) findViewById(R.id.t_jiameng);
        t_jiameng.setOnClickListener(this);
        et_wangji = (TextView) findViewById(R.id.et_wangji);
        et_wangji.setOnClickListener(this);
        et_name = (EditText) findViewById(R.id.et_name);
        et_pass = (EditText) findViewById(R.id.et_pass);

    }


    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.bt_ok:

                if (!et_name.getText().toString().equals("") && !et_pass.getText().toString().equals("")) {
                    MyApplication.myviewutil.startProgressDialog(LoginActivity.this);
                    new PostLogin(et_name.getText().toString(), UtilMD5.MD5EncodeCount(et_pass.getText().toString(), "", 2), new AsyCallBack<PostLogin.Info>() {
                        public void onSuccess(String toast, int type, PostLogin.Info info) throws Exception {
                            super.onSuccess(toast, type, info);
                            MyApplication.myviewutil.stopProgressDialog();
                            String message = info.f;
                            if (message.equals("0")) {
                                Toast.makeText(LoginActivity.this, "登录失败，请稍后再进行尝试", Toast.LENGTH_SHORT).show();
                            }
                            if (message.equals("1")) {
                                Toast.makeText(LoginActivity.this, "登录成功", Toast.LENGTH_SHORT).show();
                                finish();
                                startActivity(new Intent(LoginActivity.this, MainActivity.class));
                                MyApplication.myPreferences.saveUid(info.h);
                                MyApplication.myPreferences.savePassword(et_pass.getText().toString());
                                MyApplication.myPreferences.saveMobile(et_name.getText().toString());

                            }
                            if (message.equals("2")) {
                                Toast.makeText(LoginActivity.this, "手机号码不存在，请检查后重新尝试", Toast.LENGTH_SHORT).show();
                            }
                            if (message.equals("3")) {
                                Toast.makeText(LoginActivity.this, "密码错误，请检查后重新尝试", Toast.LENGTH_SHORT).show();
                            }
                            if (message.equals("4")) {
                                Toast.makeText(LoginActivity.this, "您还未审核通过", Toast.LENGTH_SHORT).show();
                            }
                        }

                        public void onFail(String toast, int type) throws Exception {
                            super.onFail(toast, type);
                            MyApplication.myviewutil.stopProgressDialog();
                            Toast.makeText(LoginActivity.this, "登录失败，请检查您的网络后再进行尝试", Toast.LENGTH_SHORT).show();
                        }
                    }).execute(LoginActivity.this);
                } else {
                    Toast.makeText(LoginActivity.this, "账号或密码不能为空", Toast.LENGTH_SHORT).show();
                }


                break;
            case R.id.t_jiameng:

                startActivity(new Intent(LoginActivity.this, JiaMengActivity.class));


                break;
            case R.id.et_wangji:

                startActivity(new Intent(LoginActivity.this, ForgetActivity.class));

                break;
        }
    }

}
